package com.example.designPattern.Proxy.JDKDynamicProxy;

import java.lang.reflect.Method;


public class StarCompany implements  MyInvocationHandler {

    private Object target;
    public Object getInstance(Object IStar) throws Exception{
        this.target = IStar;
        Class<?> clazz = target.getClass();
        return StarProxy.newProxyInstance(new MyClassLoader(),clazz.getInterfaces(),this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(this.target,args);
        after();
        return obj;
    }

    private void before(){
        System.out.println("我是明星经纪人公司，开始寻求投资商。");
        System.out.println("开始物色");
    }

    private void after(){
        System.out.println("OK的话，准备开办演唱会");
    }
}
